/********************************************************************************
 *    Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
 *                                                                              *
 *              This software is distributed under the terms of the * GNU Lesser
 *General Public Licence (LGPL) version 3,             * copied verbatim in the
 *file "LICENSE"                       *
 ********************************************************************************/
#ifndef HIDAQUNPACKTASk_H
#define HIDAQUNPACKTASk_H

// #include "TClonesArray.h"
#include "FairTask.h"

#include <string>
using std::string;

class TClonesArray;

class HiDaqUnpackTask : public FairTask {
public:
  /** Default constructor **/
  HiDaqUnpackTask();

  /** Constructor with parameters (Optional) **/
  HiDaqUnpackTask(string inputrawfile, Bool_t savetotree);

  /** Destructor **/
  ~HiDaqUnpackTask();

  /** Initiliazation of task at the beginning of a run **/
  virtual InitStatus Init();

  /** ReInitiliazation of task when the runID changes **/
  virtual InitStatus ReInit();

  /** Executed for each event. **/
  virtual void Exec(Option_t *opt);

  /** Load the parameter container from the runtime database **/
  virtual void SetParContainers();

  /** Finish task called at the end of the run **/
  virtual void Finish();

  // Setters -----------------------

  // Getters -----------------------
  Int_t GetTotalTSNum() const { return fMaxTSNum; }
  std::ifstream* GetInputFileStream() const { return fInputFile; }

  // Methods -----------------------
  void ReadHeader(std::ifstream* fin);

private:
  /** Input array from previous already existing data level **/
  //  TClonesArray* <InputDataLevel>;

  /** Output array to  new data level**/
  //  TClonesArray* <OutputDataLevel>;

  

  string fInputRawFileName{}; // 原始文件名
  std::ifstream* fInputFile{};  // 原始文件流指针
  TClonesArray* fDaqInfoArray{};      // DAQ信息数组
  std::vector<std::pair<uint64_t, uint64_t>> fTSAddressList; // 时间片-地址列表

  Bool_t fSaveToTree = kTRUE; // 是否保存到tree
  Int_t fMaxTSNum = 0;        // 原始文件中最大时间片数量

  Int_t fCurrentTSIndex = 0;    // 当前处理时间片索引

  HiDaqUnpackTask(const HiDaqUnpackTask &);
  HiDaqUnpackTask operator=(const HiDaqUnpackTask &);

  ClassDef(HiDaqUnpackTask, 1);
};

#endif
